/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.tool;

import com.funcom.peeler.WorkBench;

import java.awt.*;
import java.awt.event.MouseEvent;

public abstract class DraggingTool extends Tool {

    Point move_delta = new Point();
    Point start_end_delta = new Point();
    Point start_point;
    Point end_point;
    Point prev_point;

    public DraggingTool( WorkBench workbench ) {
        super( workbench );
    }

    protected void updateDelta( MouseEvent e ) {

        Point new_point = e.getPoint();

        move_delta.x = new_point.x - prev_point.x;
        move_delta.y = new_point.y - prev_point.y;

        prev_point = end_point;
        end_point = new_point;

        start_end_delta.x = end_point.x - start_point.x;
        start_end_delta.y = end_point.y - start_point.y;
    }

    protected void deInit() {

        if ( change != null ) {
            change.endChange();
            workbench.pushChange(change);
        }

        workbench.popTool();

        change = null;

        start_point = null;
        end_point = null;
        prev_point = null;
    }
}
